def f(n):
    if n<2:
        return 0
    elif n==2:
        return 1
    elif n>2:
        return n//3+f(n//3+n%3)
while True:
    try:
        n=int(input())
        if n!=0:
            print(f(n))
    except:
        break